package com.flyu.mySocket;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class UrlDown {
    public static void main(String[] args) throws Exception {
        // 下载地址
        URL url = new URL("https://m801.music.126.net/20220130220332/55d82842f80e6e43ce1cdab8dd024f7c/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/11983357028/fa35/71e6/ecfb/e58acc011ea31f62f8aad4bb0ce96846.m4a");
        // 连接资源
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        InputStream inputStream = urlConnection.getInputStream();

        FileOutputStream fos = new FileOutputStream("孤勇者.m4a");

        byte[] buffer = new byte[1024];
        int len;
        while ((len=inputStream.read(buffer))!=-1){
            fos.write(buffer,0, len);
        }
        fos.close();
        inputStream.close();
        urlConnection.disconnect();

    }
}
